package wwl.lsf.hellospringboot.easyExcel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import wwl.lsf.hellospringboot.baidu.HttpUtil;
import wwl.lsf.hellospringboot.common.BizResponse;
import wwl.lsf.repository.LetCodeMapper;
import wwl.lsf.tools.EveryBody考勤VO;
import wwl.lsf.tools.考勤VO;
import wwl.lsf.utils.RedisUtils;

import javax.annotation.PostConstruct;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @Title
 * @Author wangwenliang
 * @Date 2020/9/17
 * @Description
 */
@Controller
@RequestMapping("/easyExcel")
@Slf4j
public class EasyExcelController {

    private static List<EveryBody考勤VO> allvoList = new ArrayList<>();

    private static Map<String, String> nameEmployeeIdMap = new HashMap();


    @Autowired
    private LetCodeMapper letCodeMapper;

    @Autowired
    private RedisUtils redisUtils;


    @PostMapping("/execute")
    @ResponseBody
    public Object upload(@RequestBody Map<String, String> sql) throws IOException {
        List<Map<String, Object>> sql1 = letCodeMapper.executeQuerySql(sql.get("sql"));
        JSONArray objects = new JSONArray();
        JSONArray colResult = new JSONArray();
        colResult.add(objects);
        AtomicInteger keyCount = new AtomicInteger(0);

        if (CollectionUtils.isNotEmpty(sql1)) {
            if (sql1.get(0) != null) {
                sql1.get(0).forEach((k, v) -> {
                    JSONObject colOne = new JSONObject();
//                    colOne.put("key", "0-" + Integer.valueOf(keyCount.getAndIncrement()));
                    colOne.put("field", k);
                    colOne.put("title", k);
//                    colOne.put("hide", false);
//                    colOne.put("type", "normal");
//                    colOne.put("width", 0);
                    objects.add(colOne);
                });
            }

        }
        AtomicInteger count = new AtomicInteger(0);
        JSONObject result = new JSONObject();
        result.put("cols", colResult);
        JSONArray tableDataResult = new JSONArray();
        List exprot = new ArrayList();
        sql1.forEach(oo -> {
            JSONObject jsonObject = new JSONObject(oo);
            oo.entrySet().forEach(
                    k -> {
                        Object value = k.getValue();
                        if (value instanceof Date) {
                            //
                            String format = DateFormatUtils.format((Date) value, "yyyy-MM-dd HH:mm:SS");
                            oo.put(k.getKey(), format);
                        } else if (value instanceof Timestamp) {
                            Timestamp t = (Timestamp) value;
                            Date date = new Date(t.getTime());
                            String format = DateFormatUtils.format((Date) date, "yyyy-MM-dd HH:mm:SS");
                            oo.put(k.getKey(), format);
                        }
                        System.out.println(111);

                    });
//            jsonObject.put("LAY_TABLE_INDEX", Integer.valueOf(count.getAndIncrement()));
            DemoData data = JSON.toJavaObject(jsonObject, DemoData.class);
            exprot.add(data);
            tableDataResult.add(new JSONObject(oo));
        });

/*
        String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
        // 这里 需要指定写用哪个class去写
        ExcelWriter excelWriter = null;
        try {
            excelWriter = EasyExcel.write(fileName, DemoData.class).build();
            WriteSheet writeSheet = EasyExcel.writerSheet("模板").build();
            excelWriter.write(exprot, writeSheet);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }*/
        result.put("tableData", tableDataResult);
        return result;
    }

    @PostMapping("/kaoqin")
    @ResponseBody
    public Object kaoqin(@RequestBody Map<String, String> kaoqin) throws Exception {
        Map<String, String> headerMap = new HashMap<>();

        if (StringUtils.isEmpty(nameEmployeeIdMap.get(kaoqin.get("employeeId")))) {
            throw new RuntimeException("数据找不到,请联系管理员录入");
        }
        headerMap.put("Cookie", kaoqin.get("Cookie"));
        JSONObject result = null;
        String employeeIdQueryKey = "select * from kaoqin_zfz where month='%s' and employeeId='%s' and query_day='%s'";
        String nowstr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        List<Map<String, Object>> maps = letCodeMapper.executeQuerySql(String.format(employeeIdQueryKey, kaoqin.get("month"), nameEmployeeIdMap.get(kaoqin.get("employeeId")), nowstr));
        if (CollectionUtils.isEmpty(maps) || maps.get(0).get("data") == null) {
            String url = String.format("http://eip.hengchang6.com/api/portal/compo/attendance/composite_info?month=%s&employeeId=%s", kaoqin.get("month"), nameEmployeeIdMap.get(kaoqin.get("employeeId")));
            String s1 = HttpUtil.httpGet(url, headerMap);
            if (StringUtils.isEmpty(s1) || !StringUtils.equals(JSON.parseObject(s1).get("code").toString(), "200")) {
                throw new RuntimeException("查询eip不通,看看是不是cookie失效了");
            }
            result = getJsonObject(s1, kaoqin.get("jiabanavgmin"));
            String employeeIdInsertKey = "INSERT INTO kaoqin_zfz(`month`, `employeeId`, `query_day`, `data`) VALUES ('%s','%s','%s','%s');";
            letCodeMapper.executeSql(String.format(employeeIdInsertKey, kaoqin.get("month"), nameEmployeeIdMap.get(kaoqin.get("employeeId")), nowstr, s1));
        } else {
            result = getJsonObject(maps.get(0).get("data").toString(), kaoqin.get("jiabanavgmin"));
        }
       /* Object name = redisUtils.get(String.format(employeeIdQueryKey, kaoqin.get("month"), nameEmployeeIdMap.get(kaoqin.get("employeeId")), nowstr));
        JSONObject result = null;
        if (name == null) {
            String url = String.format("http://eip.hengchang6.com/api/portal/compo/attendance/composite_info?month=%s&employeeId=%s", kaoqin.get("month"), nameEmployeeIdMap.get(kaoqin.get("employeeId")));
            String s1 = HttpUtil.httpGet(url, headerMap);
            result = getJsonObject(s1, kaoqin.get("jiabanavgmin"));
            redisUtils.set(String.format(employeeIdQueryKey, kaoqin.get("month"), nameEmployeeIdMap.get(kaoqin.get("employeeId")), nowstr), s1, 1000 * 60 * 60 * 24);
        } else {
            result = getJsonObject(name.toString(), kaoqin.get("jiabanavgmin"));
        }*/
        return result;
    }

    @PostMapping("/zfzkaoqin")
    @ResponseBody
    public Object zfzkaoqin(@RequestBody Map<String, String> zfzkaoqin) throws Exception {
        JSONObject result = new JSONObject();
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("Cookie", zfzkaoqin.get("Cookie"));
        List<EveryBody考勤VO> listResult = new ArrayList<>();

        if (StringUtils.equals(zfzkaoqin.get("employeeId"), "分组")) {
            String groups[] = {
                    "产品组"
                    , "研发组"
                    , "测试组"
                    , "支付组"
                    , "个贷组"
                    , "资产组"
                    , "通用组"
                    , "签约组"
                    , "前端组"
            };
            List<EveryBody考勤VO> fendui = new ArrayList<>();

            for (String group : groups) {
                zfzkaoqin.put("employeeId", group);
                List<EveryBody考勤VO> list = getEveryBody考勤VOS(zfzkaoqin);
                List<EveryBody考勤VO> everyBody考勤VOS = getEveryBody考勤VOS(zfzkaoqin, headerMap, list);
                listResult.addAll(everyBody考勤VOS);
                fendui.add(everyBody考勤VOS.get(0));
            }
            fendui = fendui.stream().sorted(Comparator.comparing(EveryBody考勤VO::getJiabanshichang).reversed()).collect(Collectors.toList());
            listResult.addAll(fendui);


        } else {
            List<EveryBody考勤VO> list = getEveryBody考勤VOS(zfzkaoqin);

            listResult = getEveryBody考勤VOS(zfzkaoqin, headerMap, list);
        }

        JSONArray objects = new JSONArray();
        JSONArray colResult = new JSONArray();
        colResult.add(objects);

        Field[] fields = EveryBody考勤VO.class.getDeclaredFields();
        for (Field field : fields) {
            if (field.getAnnotation(ExcelProperty.class) != null) {
                JSONObject colOne = new JSONObject();
//                    colOne.put("key", "0-" + Integer.valueOf(keyCount.getAndIncrement()));
                colOne.put("field", field.getName());
                colOne.put("title", field.getAnnotation(ExcelProperty.class).value());
//                    colOne.put("hide", false);
//                    colOne.put("type", "normal");
//                    colOne.put("width", 0);
                objects.add(colOne);
            }

        }
        result.put("cols", colResult);
        result.put("tableData", listResult);
        return result;
    }

    /**
     * 根据前端参数动态返回被计算数据
     *
     * @param zfzkaoqin
     * @return
     */
    private List<EveryBody考勤VO> getEveryBody考勤VOS(Map<String, String> zfzkaoqin) {
        //每次查询数据库这样不用重启,可以注释掉提高效率
        initKaoqinVO();
        //给人打标计的应对部门变换
        String version = "-new";
        List<EveryBody考勤VO> list = new ArrayList();
        if (StringUtils.equals("支付组", zfzkaoqin.get("employeeId")) || StringUtils.equals("1", zfzkaoqin.get("employeeId"))) {
            List<EveryBody考勤VO> 支付组 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("支付"+version);
            }).collect(Collectors.toList());
            list.addAll(支付组);
        } else if (StringUtils.equals("产品组", zfzkaoqin.get("employeeId"))) {
            //产品组
            List<EveryBody考勤VO> 产品组 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("产品"+version);
            }).collect(Collectors.toList());
            list.addAll(产品组);
        } else if (StringUtils.equals("测试组", zfzkaoqin.get("employeeId"))) {
            //测试组
            List<EveryBody考勤VO> 测试组 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("测试"+version);
            }).collect(Collectors.toList());
            list.addAll(测试组);
        }
//        else if (StringUtils.equals("房贷组", zfzkaoqin.get("employeeId"))) {
//            List<EveryBody考勤VO> 房贷组 = allvoList.stream().filter(vv -> {
//                return vv.getGroupName().contains("房贷组");
//            }).collect(Collectors.toList());
//            list.addAll(房贷组);
////            list.add(new EveryBody考勤VO("任杰", 0, "", "10430464"));
////            list.add(new EveryBody考勤VO("王俊", 0, "", "10430671"));
//        }
//        else if (StringUtils.equals("车贷组", zfzkaoqin.get("employeeId"))) {
//            //车贷研发组
//            List<EveryBody考勤VO> 车贷组 = allvoList.stream().filter(vv -> {
//                return vv.getGroupName().contains("车贷组");
//            }).collect(Collectors.toList());
//            list.addAll(车贷组);
//        }
        else if (StringUtils.equals("研发组", zfzkaoqin.get("employeeId"))) {
            //研发组
            List<EveryBody考勤VO> 研发组 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("研发"+version);
            }).collect(Collectors.toList());
            list.addAll(研发组);
        } else if (StringUtils.equals("前端组", zfzkaoqin.get("employeeId"))) {
            //前端组
            List<EveryBody考勤VO> 前端组 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("前端"+version);
            }).collect(Collectors.toList());
            list.addAll(前端组);
        } else if (StringUtils.equals("个贷组", zfzkaoqin.get("employeeId"))) {
            //个贷研发组
            List<EveryBody考勤VO> 个贷组 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("个贷"+version);
            }).collect(Collectors.toList());
            list.addAll(个贷组);

        } else if (StringUtils.equals("资产组", zfzkaoqin.get("employeeId"))) {
            //资产研发组
            List<EveryBody考勤VO> 资产组 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("资产"+version);
            }).collect(Collectors.toList());
            list.addAll(资产组);

        } else if (StringUtils.equals("通用组", zfzkaoqin.get("employeeId"))) {
            //通用研发组
            List<EveryBody考勤VO> 通用组 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("通用"+version);
            }).collect(Collectors.toList());
            list.addAll(通用组);

        } else if (StringUtils.equals("签约组", zfzkaoqin.get("employeeId"))) {
            //签约研发组
            List<EveryBody考勤VO> 签约组 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("签约"+version);
            }).collect(Collectors.toList());
            list.addAll(签约组);

        }
//        else if (StringUtils.equals("资金组", zfzkaoqin.get("employeeId"))) {
//            //资金组研发组
//            List<EveryBody考勤VO> 资金组 = allvoList.stream().filter(vv -> {
//                return vv.getGroupName().contains("资金组");
//            }).collect(Collectors.toList());
//            list.addAll(资金组);
//        }
        else {
            //资金组研发组
            List<EveryBody考勤VO> 本部门 = allvoList.stream().filter(vv -> {
                return vv.getGroupName().contains("本部"+version);
            }).collect(Collectors.toList());
            list.addAll(本部门);
        }
        return list;
    }

    /**
     * 根据原始人员信息计算考勤数据,返回计算后的实体
     *
     * @param zfzkaoqin
     * @param headerMap
     * @param list
     * @return
     * @throws Exception
     */
    private List<EveryBody考勤VO> getEveryBody考勤VOS(Map<String, String> zfzkaoqin, Map<String, String> headerMap, List<EveryBody考勤VO> list) throws Exception {
        for (EveryBody考勤VO everyBody考勤VO : list) {
            String s1 = "";
            String employeeIdQueryKey = "select * from kaoqin_zfz where month='%s' and employeeId='%s' and query_day='%s'";
            String nowstr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            List<Map<String, Object>> maps = letCodeMapper.executeQuerySql(String.format(employeeIdQueryKey, zfzkaoqin.get("month"), everyBody考勤VO.getEmployeeId(), nowstr));
            if (CollectionUtils.isEmpty(maps) || maps.get(0).get("data") == null) {
                String url = String.format("http://eip.hengchang6.com/api/portal/compo/attendance/composite_info?month=%s&employeeId=%s", zfzkaoqin.get("month"), everyBody考勤VO.getEmployeeId());
                s1 = HttpUtil.httpGet(url, headerMap);
                if (StringUtils.isEmpty(s1) || !StringUtils.equals(JSON.parseObject(s1).get("code").toString(), "200")) {
                    throw new RuntimeException("查询eip不通,看看是不是cookie失效了");
                }
                String employeeIdInsertKey = "INSERT INTO kaoqin_zfz(`month`, `employeeId`, `query_day`, `data`) VALUES ('%s','%s','%s','%s');";
                letCodeMapper.executeSql(String.format(employeeIdInsertKey, zfzkaoqin.get("month"), everyBody考勤VO.getEmployeeId(), nowstr, s1));
            } else {
                s1 = maps.get(0).get("data").toString();

            }
            JSONObject everybodyresult = getJsonObject(s1, null);
            if (everybodyresult.get("avgmined") != null) {
                everyBody考勤VO.setJiabanshichang(Integer.valueOf(everybodyresult.get("avgmined").toString()));
                everyBody考勤VO.setJiabanshichang_min(Integer.valueOf(everybodyresult.get("jiabanshichang_min").toString()));
            }
        }
        // 方法2：使用集合的removeIf()方法
        list.removeIf(new Predicate<EveryBody考勤VO>() {
            @Override
            public boolean test(EveryBody考勤VO s) {
                return s.getJiabanshichang() == 0;
            }
        });
        list = list.stream().sorted(Comparator.comparing(EveryBody考勤VO::getJiabanshichang).reversed()).collect(Collectors.toList());
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setSequence(i + 1 + "");

        }
        double asDouble = list.stream().mapToInt(EveryBody考勤VO::getJiabanshichang).average().getAsDouble();
        double asDouble_min = list.stream().mapToInt(EveryBody考勤VO::getJiabanshichang_min).average().getAsDouble();
        EveryBody考勤VO everyBody考勤VO_xfd = new EveryBody考勤VO(zfzkaoqin.get("employeeId") + "小分队", (int) asDouble, "专业写bug团伙", "");
        everyBody考勤VO_xfd.setJiabanshichang_min((int) asDouble_min);
        list.add(0, everyBody考勤VO_xfd);
        return list;
    }

    private JSONObject getJsonObject(String kaoqin1, String jiabanavgminstr) {
        JSONObject result = new JSONObject();
        JSONArray objects = new JSONArray();
        JSONArray colResult = new JSONArray();
        colResult.add(objects);

        Field[] fields = 考勤VO.class.getDeclaredFields();
        for (Field field : fields) {
            JSONObject colOne = new JSONObject();
//                    colOne.put("key", "0-" + Integer.valueOf(keyCount.getAndIncrement()));
            colOne.put("field", field.getName());
            colOne.put("title", field.getAnnotation(ExcelProperty.class).value());
//                    colOne.put("hide", false);
//                    colOne.put("type", "normal");
//                    colOne.put("width", 0);
            objects.add(colOne);

        }
        result.put("cols", colResult);
        JSONObject parse = JSON.parseObject(kaoqin1);
        JSONObject data1 = (JSONObject) parse.get("data");
        List<考勤VO> voList = JSON.parseArray(JSON.toJSONString(data1.get("days")), 考勤VO.class);//转换成vo
        int avgcount = 0;
        int totalmin = 0;
        Date maxDate = new Date();
        voList = voList.stream().sorted(Comparator.comparing(考勤VO::getDate).reversed()).collect(Collectors.toList());

        for (考勤VO vo : voList) {
            if (vo.getPunchBegin() != null && vo.getPunchBegin().getHours() >= 9) {
                vo.getPunchBegin().setHours(9);
                vo.getPunchBegin().setMinutes(0);
                vo.getPunchBegin().setSeconds(0);
            }
            if (vo.getPunchEnd() != null && vo.getPunchEnd().getHours() < 18) {
                vo.getPunchEnd().setHours(18);
                vo.getPunchEnd().setMinutes(0);
                vo.getPunchEnd().setSeconds(0);
            }
            if (vo.getPunchBegin() != null && vo.getPunchEnd() != null) {

//                如果考勤跨天了就认为当天23点5959的计算,其实应该是跨天了早晨按照6点晚上12点算,后续在优化吧
                int dateend = vo.getPunchEnd().getDate();
                int datebegin = vo.getPunchBegin().getDate();
                if (dateend > datebegin) {
                    vo.getPunchEnd().setDate(datebegin);
                    vo.getPunchEnd().setHours(23);
                    vo.getPunchEnd().setMinutes(59);
                    vo.getPunchEnd().setSeconds(59);
                }

                long begin = vo.getPunchBegin().getTime();
                long end = vo.getPunchEnd().getTime();
                BigDecimal totalhaomiao = new BigDecimal(end).subtract(new BigDecimal(begin));
                BigDecimal worktime = new BigDecimal(32400000);
                BigDecimal divide = totalhaomiao.subtract(worktime).divide(new BigDecimal(60000), 0, BigDecimal.ROUND_HALF_EVEN);

                vo.setJiabanshichang(divide.longValue());


            }
            if (vo.getJiabanshichang() != null) {
                avgcount++;
                totalmin += vo.getJiabanshichang();
            }
            if (vo.getNormalNotes() == null && vo.getPunchBegin() == null && vo.getPunchEnd() == null) {
                vo.setNormalNotes("今天休息日,老子不上班");
            }

            //算出最大日期
        }
        考勤VO pingjun = new 考勤VO();
        //防止空指针优化的
        if (avgcount == 0) {
            pingjun.setNormalNotes("参与计算有效天数为:" + avgcount + "天");
        } else {
            LocalDate now1 = LocalDate.now();
            int remainDays = countWorkDay(now1.getYear(), now1.getMonthValue(), now1.getDayOfMonth());
            String string6 = new BigDecimal(totalmin).divide(new BigDecimal(avgcount), 0, BigDecimal.ROUND_HALF_EVEN).toString();
            if (StringUtils.isEmpty(jiabanavgminstr)) {
                jiabanavgminstr = "60";
            }
            int jiabanavgmin = Integer.valueOf(jiabanavgminstr);
            int remainTotalMins = (avgcount + remainDays) * jiabanavgmin - totalmin;
            String s = new BigDecimal(totalmin).divide(new BigDecimal(avgcount + remainDays), 0, BigDecimal.ROUND_HALF_EVEN).toString();

            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("为达成每天进步").append(jiabanavgminstr).append("分钟目标,")
                    .append("还有")
                    .append(remainDays)
                    .append("次提高机会,本月还需奉献总时长")
                    .append(remainTotalMins / 60)
                    .append("小时")
                    .append(remainTotalMins - remainTotalMins / 60 * 60)
                    .append("分钟,大体意思就是从今天开始每天至少需进步")
                    .append(remainTotalMins / remainDays)
                    .append("分钟")
                    .append("但是呢老子想躺平依然能够日均")
                    .append(s)
                    .append("分钟");
            result.put("suanguaresult", stringBuilder);
            result.put("jiabanshichang_min", s);
            result.put("avgmined", string6);
            pingjun.setNormalNotes("参与计算有效天数为:" + avgcount + "天,平均每天加班" + string6 + "分");
            pingjun.setJiabanshichang(Long.valueOf(string6));
        }

        voList.add(0, pingjun);
        result.put("tableData", voList);
        return result;
    }

    public static int countWorkDay(int year, int month, int start) {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        // 月份是从0开始du计算，所以需要减去1
        c.set(Calendar.MONTH, month - 1);
        // 当月最后一天的日期dao
        int max = c.getActualMaximum(Calendar.DAY_OF_MONTH);
        // 开始日期为传入
        // 计数
        int count = 0;
        while (start <= max) {
            c.set(Calendar.DAY_OF_MONTH, start);
            if (isWorkDay(c)) {
                count++;
            }
            start++;
        }
        return count;
    }

    // 判断是否工作日（未排除法定节假日，由于涉及到农历节日，处理很麻烦）
    public static boolean isWorkDay(Calendar c) {
        // 获取星期,1~7,其中1代表星期日，2代表星期一 ... 7代表星期六
        int week = c.get(Calendar.DAY_OF_WEEK);
        // 不是周六和周日的都认为是工作日
        return week != Calendar.SUNDAY && week != Calendar.SATURDAY;
    }

    /**
     * 文件上传
     * <p>
     * 1. 创建excel对应的实体对象 参照{@link UploadData}
     * <p>
     * 2. 由于默认一行行的读取excel，所以需要创建excel一行一行的回调监听器，参照{@link UploadDataListener}
     * <p>
     * 3. 直接读即可
     */
    @PostMapping("/upload")
    @ResponseBody
    public Object upload(MultipartFile file) throws IOException {

        String name = file.getName();
        String originalFilename = file.getOriginalFilename();
        ExcelTypeEnum excelTypeEnum = ExcelTypeEnum.XLSX;
        if (StringUtils.endsWith(originalFilename, ExcelTypeEnum.XLS.getValue())) {
            excelTypeEnum = ExcelTypeEnum.XLS;
        }
      /*  else if (StringUtils.endsWith(originalFilename, ExcelTypeEnum.CSV.getValue())) {
            excelTypeEnum = ExcelTypeEnum.CSV;
        }*/

        DemoDataListener demoDataListener = new DemoDataListener(letCodeMapper);
        EasyExcel.read(file.getInputStream(), demoDataListener).excelType(excelTypeEnum).sheet().doRead();
        BizResponse success = new BizResponse("0000", "success");
        success.setData(demoDataListener.getSelectTableSql().toString());
        return success;
    }

    @PostMapping("/upload22")
    @ResponseBody
    public Object upload(String fileName) throws IOException {

        fileName = "C:\\Users\\Administrator\\Documents\\WXWork\\1688850530930338\\Cache\\File\\2022-10\\恒慧融在途存管编号【非质保金融担代偿合同】.xls";

        DemoDataListener demoDataListener = new DemoDataListener(letCodeMapper);
        File file = new File(fileName);
        EasyExcel.read(file, demoDataListener).sheet().doRead();
        BizResponse success = new BizResponse("0000", "success");
        success.setData(demoDataListener.getSelectTableSql().toString());
        return success;
    }

    /**
     * 最简单的写
     * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
     * <p>2. 直接写即可
     */
    @RequestMapping("/{count}")
    @ResponseBody
    public String simpleWrite(@PathVariable("count") Integer count) {
       /* // 写法1
        String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
        // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
        // 如果这里想使用03 则 传入excelType参数即可
        EasyExcel.write(fileName, DemoData.class).sheet("模板").doWrite(data());*/

        // 写法2
        String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
        // 这里 需要指定写用哪个class去写
        ExcelWriter excelWriter = null;
        try {
            excelWriter = EasyExcel.write(fileName, DemoData.class).build();
            WriteSheet writeSheet = EasyExcel.writerSheet("模板").build();
            excelWriter.write(data(count), writeSheet);
        } finally {
            // 千万别忘记finish 会帮忙关闭流
            if (excelWriter != null) {
                excelWriter.finish();
            }
        }
        return "写完了";
    }

    private List<DemoData> data(Integer count) {
        List<DemoData> list = new ArrayList<DemoData>();
        for (int i = 0; i < count; i++) {
            DemoData data = new DemoData();
            data.setString("字符串" + i);
            data.setDate(new Date());
            data.setDoubleData(0.56);
            list.add(data);
        }
        return list;
    }

    @PostConstruct
    public void initKaoqinVO() {

        String initSql = "select * from everybody_info ";
        List<Map<String, Object>> maps = letCodeMapper.executeQuerySql(initSql);

        allvoList = JSON.parseArray(JSON.toJSONString(maps), EveryBody考勤VO.class);//转换成vo
        for (int i = 0; i < allvoList.size(); i++) {
            allvoList.get(i).setJiabanshichang(0);
            nameEmployeeIdMap.put(allvoList.get(i).getName(), allvoList.get(i).getEmployeeId());
        }

    }


}
